package com.weimob.demo.common.no;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Version工具类
 * @author lenovo
 *
 */
public class VersionProvider {

	private static Map<String, Version> container = new ConcurrentHashMap<String, Version>();

	/**
	 * 
	 * @param btype
	 * @return
	 */
	public static String getVersion(String btype) {
		return "";
	}

	/**
	 * 安全Cache，如果Version被用光，清理Version在重新生成
	 * @param btype
	 * @return
	 */
	public static String getVersionSofttCache(String btype) {

		if (!container.containsKey(btype)) {
			Version version = new Version(btype, new ClearVersionObserver());
			container.put(btype, version);
		}
		return container.get(btype).getVersion();
	}

	/**
	 * 缓存Cache，如果Version被用光，重新取得Version
	 * @param btype
	 * @return
	 */
	public static String getVersionCache(String btype) {

		if (!container.containsKey(btype)) {
			Version version = new Version(btype, new CarryOnVersionObserver());
			container.put(btype, version);
		}
		return container.get(btype).getVersion();
	}

	/**
	 * 清理Cache中的Version
	 * @param btype
	 */
	public static void clearVersion(String btype) {
		container.remove(btype);
	}
}
